import { realtimeValidate } from './validators/classifier.js';
import { loadLocale, t } from './locales/lang-loader.js';

document.addEventListener('DOMContentLoaded', async () => {
  // 初始化多语言
  const langData = await loadLocale('zh-CN');
  document.querySelector('.dropdown-input').placeholder = t('classifier.placeholder');

  // 初始化验证
  realtimeValidate(document.querySelector('.dropdown-input'));

  // 动态生成选项
  const dropdownList = document.querySelector('.dropdown-list');
  langData.classifier.categories.forEach(cat => {
    const li = document.createElement('li');
    li.className = 'dropdown-item';
    li.textContent = cat.name;
    li.addEventListener('click', () => {
      document.querySelector('.dropdown-input').value = cat.name;
      dropdownList.classList.remove('dropdown-list-active');
      dropdownList.classList.add('dropdown-list-inactive');
    });
    dropdownList.appendChild(li);
  });
});